<template>
  <div>callback</div>
</template>

<script>
import * as wxApi from "@/api/wx";

export default {
  async mounted() {
    console.log("mounted ad wx/callbak.vue", JSON.stringify(this.$route.query));
    const key = (this.$route.query || {}).key || "";
    const code = (this.$route.query || {}).code;
    // 拿到 code后传递到后端，由后端获取assess_token
    await wxApi.getAccessTokenByCode({ code });
    // console.log("resp", resp);
    const resp2 = await wxApi.getWxUserInfo();
    this.$store.commit("SET_WX_USERINFO", resp2);
    // 获取到用户信息后，跳转到填写表单的页面
    this.$router.replace(`/?key=${key}`);
  },
};
</script>

<style></style>
